package com.twu.biblioteca;

import java.util.Scanner;

public class BibliotecaApp {

    public static void main(String[] args) {
        Biblioteca biblioteca = new Biblioteca();
        signIn(biblioteca);
        while (true) {
            showWelcome();
            selectOption(biblioteca);
        }
    }

    private static void signIn(Biblioteca biblioteca) {
        Scanner scanner = new Scanner(System.in);
        String username = scanner.nextLine();
        String password = scanner.nextLine();
        while (!biblioteca.signIn(username, password)) signIn(biblioteca);
    }

    static void showWelcome() {
        System.out.println("---------------------");
        System.out.println("Welcome to Biblioteca");
        System.out.println("---------------------");
        System.out.println("Please choose an option:");
        System.out.println("1. view books");
        System.out.println("2. reserve book");
        System.out.println("3. check membership");
        System.out.println("4. view movie");
    }

    static void selectOption(Biblioteca biblioteca) {
        Scanner scanner = new Scanner(System.in);
        String commandOption = scanner.nextLine();
        if (!commandOption.matches("[1-4]")) System.out.println("Select a valid option!!");
        else {
            Command command = null;
            if (commandOption.equals("1")) {
                command = new ViewBooksCommand(biblioteca);
            } else if (commandOption.equals("2")) {
                command = new ReserveCommand(biblioteca);
            } else if (commandOption.equals("3")) {
                command = new CheckMembershipCommand(biblioteca);
            } else if (commandOption.equals("4")) {
                command = new ViewMoviesCommand(biblioteca);
            }
            if (command != null) command.execute();
        }
    }
}
